<?php
namespace app\common\component\user_activation;

use app\common\model\UserActivation;

class UserActivationService {
	public function getUserActivationId($user_id) {
		$getUserActivation = UserActivation::get(['user_id' => $user_id]);

		if($getUserActivation) {
			return [
				'code' => 0,
				'data' => [
					'user_activation' => $getUserActivation
				]
			];
		} else {
			return $this -> create([
				'user_id' => $user_id,
				'price' => 0
			]);
		}
	}

	public function create($data) {
		$UserActivation = new UserActivation($data);

		if($UserActivation -> save()) {
    		return [
    			'code' => 0,
    			'message' => '创建激活码成功',
    			'data' => [
    				'user_activation' => $UserActivation
    			]
    		];
    	}

    	return [
			'code' => -1,
			'message' => '创建激活码失败'
		];
	}
}
?>